<?php 
class Controller_Admin_Module_News_Listpost extends ypAdminController {
	public function Index() {
		$this->checkLogin();
		$this->Loader->model('Admin/Module/News/Listpost');
		$this->Loader->model('News/Index');
		$this->loadLanguage('Admin/Module/News/Listpost');

		$start = isset($this->Request->GET['start_post']) ? intval($this->Request->GET['start_post']) : 0;
		$limit = isset($this->Request->GET['limit']) ? intval($this->Request->GET['limit']) : 50;

		$posts = $this->Model_Admin_Module_News_Listpost->loadPost($start, $limit);
		foreach ($posts as $offset => $content) {
			if ((int) $this->Setting->get('post_request_type') == 1) {
				$content['link'] = $this->Model_News_Index->createPostLink($content['title_alias'], $content['cat_id']);
			} else {
				$content['link'] = $this->Model_News_Index->createPostLink($content['post_id']);
			}
			$content['tags'] = $this->Model_Admin_Module_News_Listpost->loadTag($content['post_id']);
			
			$content['link_edit'] = $this->Link->build('Admin/Module/News/Edit', FALSE, array('id' => $content['post_id']));
			$content['link_delete'] = $this->Link->build('Admin/Module/News/Delete', FALSE, array('id' => $content['post_id']));
			$content['link_stat'] = $this->Link->build('Admin/Module/News/Stat', FALSE, array('id' => $content['post_id']));

			$posts[$offset] = $content;
		}

		$this->set('POSTS', $posts);
		$this->set('newpost_link', $this->Link->build('Admin/Module/News/Newpost'));

		$this->setTemplate('module/Module/News/Listpost.php');
		$this->Document->setTitle($this->_data['title']);
		$this->setTemplateChild(array(
			'Admin/System/Header',
			'Admin/System/Footer',
			'Admin/Module/News/Setting/LeftColumn'
		));
		$this->Response->setOutput($this->render());
	}
}